using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using Clue_Less_Shared.Enumerations;

namespace Clue_Less_Shared
{
    /// <summary>
    /// Abstract class - parent class of all cards
    /// </summary>
	[Serializable]
	public class Card
    {
        private string _name;
        public virtual string Name {
            get { return _name; }
            set {_name = value;}
        }

        /// <summary>
        /// Returns one of the child class instances based on card name.
        /// </summary>
        /// <param name="CardName"></param>
        /// <returns></returns>
        public static Card CreateCardFromString(string CardName)
        {
            foreach (string name in Enum.GetNames(typeof(Characters)))
            {
                if (name == CardName)
                    return new CharacterCard((Characters)Enum.Parse(typeof(Characters), name));
            }

            foreach (string name in Enum.GetNames(typeof(Weapons)))
            {
                if (name == CardName)
                    return new WeaponCard((Weapons)Enum.Parse(typeof(Weapons), name));
            }

            foreach (string name in Enum.GetNames(typeof(Rooms)))
            {
                if (name == CardName)
                   return new RoomCard((Rooms)Enum.Parse(typeof(Rooms), name));
            }

            return null;
        }
    }

    /// <summary>
    /// Child class of Card - used for weapon cards
    /// </summary>
	[Serializable]
	public class WeaponCard : Card
	{
        private Weapons _value;

        public Weapons Value
        {
            get { return _value; }
			set { _value = value; }
        }
	
		public override string Name
		{
			get { return _value.ToString(); }
            set { }
		}

		public WeaponCard(Weapons value)
        {
            _value = value;
        }

		public WeaponCard()
		{
			_value = Weapons.Empty;
		}
	}

    /// <summary>
    /// Used to communicate weapon positions between server and client
    /// </summary>
    [Serializable]
    public class WeaponPosition
    {
        private int _xPosition;

        public int XPosition
        {
          get { return _xPosition; }
          set { _xPosition = value; }
        }
        private int _yPosition;

        public int YPosition
        {
            get { return _yPosition; }
            set { _yPosition = value; }
        }

        private Weapons _weapon;

        public Weapons Weapon
        {
            get { return _weapon; }
            set { _weapon = value; }
        }


        public WeaponPosition()
        {
        }

        public WeaponPosition(int x, int y, Weapons weapon)
        {
            _xPosition = x;
            _yPosition = y;
            _weapon = weapon;
        }
    }

    /// <summary>
    /// Child class of Card - used for character cards
    /// </summary>
	[Serializable]
	public class CharacterCard : Card
	{
		private Characters _value;

		public Characters Value
        {
			get { return _value; }
			set { _value = value; }
        }

        public override string Name
        {
            get { return _value.ToString(); }
            set { }
        }

		public CharacterCard(Characters value)
        {
            _value = value;
        }

		public CharacterCard()
		{
			_value = Characters.Empty;
		}
	}

    /// <summary>
    /// Child class of Card - used for room cards
    /// </summary>
	[Serializable]
	public class RoomCard : Card
	{
		private Rooms _value;

		public Rooms Value
        {
			get { return _value; }
			set { _value = value; }
        }

        public override string Name
        {
            get { return _value.ToString(); }
            set { }
        }

		public RoomCard(Rooms value)
        {
            _value = value;
        }

		public RoomCard()
		{
			_value = Rooms.Empty;
		}
	}
}
